﻿#region 命名空间

using System;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;

#endregion

namespace Sharp.Infrastructure.Crosscutting
{
    /// <summary>
    ///     用户操作日志
    /// </summary>
    [AttributeUsage(AttributeTargets.Method)]
    public class LoggingAttribute : HandlerAttribute
    {
        /// <summary>
        ///     日志
        /// </summary>
        public LoggingAttribute()
        {
            Message = string.Empty;
            Order = 0;
        }

        /// <summary>
        ///     日志
        /// </summary>
        /// <param name="message"></param>
        public LoggingAttribute(string message)
        {
            Message = message;
            Order = 0;
        }

        /// <summary>
        /// 日志内容
        /// </summary>
        public string Message { get; set; }

        /// <summary>
        ///     创建处理器
        /// </summary>
        /// <param name="container"></param>
        /// <returns></returns>
        public override ICallHandler CreateHandler(IUnityContainer container)
        {
            var handler = new LoggingHandler(Message)
            {
                Order = Order
            };

            return handler;
        }
    }
}